package com.example.neteasecloudmusic_kotlin.ui.homepage

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.neteasecloudmusic_kotlin.R
import com.example.neteasecloudmusic_kotlin.logic.model.NavIconEntity
import kotlinx.android.synthetic.main.rv_navigation_icon.view.*
import java.util.ArrayList

class NavIconAdapter(val navIconList: ArrayList<NavIconEntity>) :
    RecyclerView.Adapter<NavIconAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val navIconName = view.navText
        val navIconId = view.navIcon
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.rv_navigation_icon, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val navIcon = navIconList[position]
        holder.navIconId.setImageResource(navIcon.iconId)
        holder.navIconName.setText(navIcon.iconName)
    }

    override fun getItemCount() = navIconList.size


}
